/**
 * 
 */
package hu.cubussapiens.facts.query;

import hu.cubussapiens.facts.Fact;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author balage
 *
 */
public class Construct implements Query {

	final Query object;
	final Query verb;
	final Query subject;
	
	public Construct(Query object, Query verb, Query subject) {
		this.object = object;
		this.verb = verb;
		this.subject = subject;
	}

	/* (non-Javadoc)
	 * @see hu.cubussapiens.facts.query.Query#execute(hu.cubussapiens.facts.query.IQueryContext)
	 */
	@Override
	public List<Long> execute(IQueryContext context) {
		if (true){ //TODO: access control
			for(Long o : object.execute(context))
				for(Long v : verb.execute(context))
					for(Long s : subject.execute(context)){
						Fact f = new Fact();
						f.setObjectID(o);
						f.setVerbID(v);
						f.setSubjectID(s);
						f.setTimestamp(new Date());
						context.getManager().makePersistent(f);
					}
		}
		
		return new ArrayList<Long>(0);
	}

}
